from RandomList import GetRandomList
from InsertionSort import insertion_sort

# 之所以代码短是引用了前面的插入排序
def bucket_sort( arr, bucket_size = 5):
    arr_min, arr_max = min(arr), max(arr)
    bucket_count = (arr_max - arr_min) // bucket_size + 1
    buckets = [[] for _ in range(bucket_count)]
    for num in arr:
        buckets[(num - arr_min) // bucket_size].append(num)
    res = []
    for bucket in buckets:
        bucket = insertion_sort(bucket)
        res.extend(bucket)
    return res

if __name__ == "__main__":
    Arr = GetRandomList(100)
    Arr = list(map(lambda x : x - 10, Arr))
    Arr = bucket_sort(Arr)
    print(Arr)